<?php
/**
 * User: 五哥派
 * Date: 2024/7/1
 * Tel(同WX): 17335592719
 */
namespace app\admin\controller\dealer;

use app\admin\controller\Base;
use app\admin\model\dealer\Apply as ApplyModel;

class Order extends Base{

    protected $model;

    public function __construct(ApplyModel $model){
        parent::__construct();
        $this->model = $model;
    }

    public function lst(){
        return $this->fetch();
    }
    public function lstajax(){
        $list = $this->model->getList();
        $result = $list->toArray();
        return showLayui($result['total'], $result['data']);
    }

    public function add(){
        if(request()->isPost()){
            $data = request()->param();
            if($this->model->saveData($data,false)){
                return success('保存成功!');
            }else{
                return error('保存失败!');
            }
        }
        return $this->fetch();
    }
    public function edit(){
        if(request()->isPost()){
            $data = request()->param();
            if($this->model->saveData($data,true)){
                return success('保存成功!');
            }else{
                return error('保存失败!');
            }
        }
        $id = input('id');
        $data = $this->model->findDataByID($id);
        $this->assign('data',$data);

        return $this->fetch();
    }

    public function del(){
        $id = input('id');
        //删除
        $res = $this->model->delDataByID($id);
        if($res){
            return success('删除成功!');
        }else{
            return error('删除失败!');
        }
    }

    public function switchStatus(){
        $id = input('get.id');
        $status = input('get.status');
        $res = $this->model->saveData(['id'=>$id,'status'=>$status],true);
        if($res){
            return success('设置成功!');
        }else{
            return error('设置失败!');
        }
    }

}

